package com.company.poker.network;

import org.jboss.netty.channel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Description of class.
 * Created 4/10/13 3:20 PM
 *
 * @author andrey.rodin@playtech.com
 */

public class DefaultMessageHandler extends SimpleChannelHandler {
    private static final Logger logger = LoggerFactory.getLogger(DefaultMessageHandler.class);

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
        String request = (String) e.getMessage();
        e.getChannel().write("HELLO WORLD" + '\n');
        logger.info(request);
    }

    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        super.channelConnected(ctx, e);
        logger.debug("host " + e.getChannel().getRemoteAddress() + " is connected");
        e.getChannel().write("[" + e.getChannel().getRemoteAddress() + "] " + "Hello" + '\n');

    }

    @Override
    public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        super.channelDisconnected(ctx, e);
        logger.debug("host " + e.getChannel().getRemoteAddress() + " is disconnected");
    }
}
